fix leak in tmpro reader.
authortsteven4@gmail.com <tsteven4@gmail.com@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 10 Jan 2014 13:07:54 +0000 (13:07 +0000)
committertsteven4@gmail.com <tsteven4@gmail.com@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 10 Jan 2014 13:07:54 +0000 (13:07 +0000)
fix leaks and generate additional fields in random reader.

git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4719 f51c46e8-681c-474f-0cfe-069cfd0219fb

gpsbabel/random.cc
gpsbabel/tmpro.cc

index cb190a973282c053c401339796129d10b4801643..da85120b516c3b8b74d57ddbf835b23c2e3a2556 100644 (file)
@@ -86,6 +86,15 @@ rand_str(const int maxlen, const char* fmt)
   }
 }
 
+static QString 
+rand_qstr(const int maxlen, const char* fmt)
+{
+  char * str = rand_str(maxlen, fmt);
+  QString qstr = QString(str);
+  xfree(str);
+  return qstr;
+}
+
 static void
 random_rd_init(const char* fname)
 {
@@ -117,13 +126,16 @@ random_read(void)
   if (doing_trks || doing_rtes) {
     head = route_head_alloc();
     if (doing_trks) {
-      head->rte_name = rand_str(8, "Trk_%s");
+      head->rte_name = rand_qstr(8, "Trk_%s");
       track_add_head(head);
     } else {
-      head->rte_name = rand_str(8, "Rte_%s");
+      head->rte_name = rand_qstr(8, "Rte_%s");
       route_add_head(head);
     }
-    head->rte_desc = rand_str(16, NULL);
+    head->rte_desc = rand_qstr(16, NULL);
+       if RND(3) {
+      head->rte_url = rand_qstr(8, "http://rteurl.example.com/%s");
+    }
   } else {
     head = NULL;
   }
@@ -138,7 +150,7 @@ random_read(void)
     fs_chain_add(&wpt->fs, (format_specific_data*) gmsd);
 
     do {
-      wpt->shortname = rand_str(8, "Wpt_%s");
+      wpt->shortname = rand_qstr(8, "Wpt_%s");
     } while (wpt->shortname == NULL);
 
     wpt->latitude = rand_dbl(180) - 90;
@@ -158,6 +170,15 @@ random_read(void)
     if RND(3) {
       WAYPT_SET(wpt, depth, rand_int(10000) / 10.0);
     }
+    if RND(3) {
+      wpt->AddUrlLink(rand_qstr(8, "http://link1.example.com/%s"));
+      if RND(3) {
+        wpt->AddUrlLink(rand_qstr(8, "http://link2.example.com/%s"));
+      }
+    }
+    if RND(3) {
+      wpt->icon_descr = rand_qstr(3, "Icon_%s");
+    }
 
     wpt->SetCreationTime(time);
     if RND(3) {
@@ -189,10 +210,10 @@ random_read(void)
         wpt->longitude = prev->longitude + (rand_dbl(1) / 100);
       }
       if RND(3) {
-        wpt->description = rand_str(16, "Des_%s");
+        wpt->description = rand_qstr(16, "Des_%s");
       }
       if RND(3) {
-        wpt->notes = rand_str(16, "Nts_%s");
+        wpt->notes = rand_qstr(16, "Nts_%s");
       }
       if RND(3) {
         GMSD_SET(addr, rand_str(8, "Adr_%s"));
index 1e5033076fba4bfef0bbbe0e84cd9d7d6a6e95f2..5684e8fc95b3b3b32187f669f53d8371f66eda65 100644 (file)
@@ -154,7 +154,7 @@ data_read(void)
       }
 
       if (i != 11) {
-        xfree(wpt_tmp);
+        waypt_free(wpt_tmp);
         warning(MYNAME ": WARNING - extracted %d fields from line %d. \nData on line ignored.\n",
                 i, linecount);
       } else {